www.gusucode.com > C++ QQ农场源代码程序 > C++ QQ农场源代码程序/code/qq农场源代码/qq农场源代码/JEINFUN.cpp
// JEINFUN.cpp: implementation of the CJEINFUN class. // ////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "SKSGODweb.h" #include "JEINFUN.h" #include <afxsock.h> #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// CJEINFUN::CJEINFUN() { } CJEINFUN::~CJEINFUN() { } //注意:要添加 "http: //参数: //dwMaxByte:最大读取数据 BOOL jein_gethtml(LPCTSTR szURL ,char *getbuf,int dwMaxByte=10240 ) { // CString str_txt; HINTERNET hInternet, hUrl; char buffer[1024]; DWORD dwBytesRead = 0; DWORD dwBytesWritten = 0; BOOL bIsFirstPacket = true; BOOL bRet = true; int nNowcopyDate =0 ; hInternet = InternetOpen("Mozilla/4.0 (compatible)", INTERNET_OPEN_TYPE_PRECONFIG, NULL,INTERNET_INVALID_PORT_NUMBER,0); if (hInternet == NULL) return 0; hUrl = InternetOpenUrl(hInternet, szURL, NULL, 0, INTERNET_FLAG_RELOAD, 0); if (hUrl == NULL) { return 0; } do { memset(buffer, 0, sizeof(buffer)); InternetReadFile(hUrl, buffer, sizeof(buffer), &dwBytesRead); //也就是一次读取 1024 bIsFirstPacket = false; // str_txt+=(CString)buffer; //添加buf nNowcopyDate =+ dwBytesRead; //加上当前读取数 if (nNowcopyDate >= dwMaxByte) { break; //已经超过我要读取的 } strcat(getbuf,buffer); //读取到的值 } while(dwBytesRead > 0); InternetCloseHandle(hUrl); InternetCloseHandle(hInternet); return 1; } //#define CTRY_SYRIA 963 // Syria int utochar(wchar_t* pUCS,char *p,int codepage) //963 { int len = 0; if(pUCS == NULL || p == NULL) return -1; len = WideCharToMultiByte(codepage,0,pUCS,-1,NULL,0,NULL,NULL); WideCharToMultiByte(codepage,0,pUCS,-1,p,len,NULL,NULL); len--; return len; } void jein_outinfo(char * formatstr,...) { va_list argptr; va_start(argptr, formatstr); char buf[4048]; wvsprintf(buf,formatstr,argptr); OutputDebugString(buf); } void TimeFormat(DWORD dwtime,char *out_time) { //将一个时间格式成本地时间 time_t t = dwtime; char tmp[64]; strftime( tmp, sizeof(tmp), "%m/%d %X ", localtime(&t) ); strcpy(out_time,tmp); } //从域名得到一个IP char* domainToIp(char *sTempDomain) { SOCKADDR_IN saddr; WORD wVersionRequested; WSADATA wsaData; int nErrorNum; wVersionRequested = MAKEWORD( 2, 2 ); nErrorNum= WSAStartup(wVersionRequested, &wsaData ); if (nErrorNum!= 0) { return "0.0.0.0"; } saddr.sin_family = AF_INET; hostent *pHostIp ; pHostIp = gethostbyname(sTempDomain); if(pHostIp == NULL) { return "0.0.0.0"; } WSACleanup(); return inet_ntoa(*(LPIN_ADDR)*(pHostIp->h_addr_list)); } //从域名得到一个 DWORD 的IP :: 为了保证兼容,加一个_ DWORD resolveIP_(char *hostName) { hostent *hent; char **addresslist; DWORD result = 0; hent = gethostbyname(hostName); if(hent) { addresslist = hent->h_addr_list; if (*addresslist) { result = *((DWORD *)(*addresslist)); } } return result; } //连接到远程主机,返回其SOCK SOCKET tcpConnect_(char *host, int port) { SOCKET sock; sock = socket(AF_INET, SOCK_STREAM, 0); if(sock == INVALID_SOCKET) return sock; sockaddr_in sin; DWORD ip = resolveIP_(host); if(ip == 0) ip = inet_addr(host); sin.sin_addr.s_addr = ip; sin.sin_family = AF_INET; sin.sin_port = htons(port); if(connect(sock, (sockaddr *)&sin, sizeof(sin)) == SOCKET_ERROR) { closesocket(sock); return INVALID_SOCKET; } return sock; } int Sock_SendPost(LPCTSTR host,CString path,CString data )//不加http 不加 ? { CString str; CString web_ref="http://imgcache.qq.com/qzone/third/happyfarm/module/Main.swf?v=33"; SOCKET S= tcpConnect_((CHAR *)host, 80); if (S==0) { // SendPost(host,path,data); return 0; } if (S==INVALID_SOCKET) { // SendPost(host,path,data); return 0; } CString con_length; con_length.Format("%d",data.GetLength()); //得到参数长度 CString url; url="POST "+path+" HTTP/1.1\r\n" +"Accept: */*\r\n" +"Referer: "+web_ref +"\r\nAccept-Language: zh-cn\r\nContent-Type: application/x-www-form-urlencoded\r\nAccept-Encoding: gzip, deflate\r\n" +"User-Agent: "+"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)" +"\r\nHost: "+host // +"cookie: fuckFUCKFUCKYOU" +"\r\nContent-Length: "+con_length +"\r\n\r\n"; url=url+data+"\r\n"; int n= send(S,url,url.GetLength() ,0); if (n<=0) { // SendPost(host,path,data); } else { } closesocket(S); return n; }